package com.hy.exception;

import com.hy.util.common.Result;
import com.hy.util.common.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(ZhentaoException.class)
    public Result handleZhentaoException(ZhentaoException e) {
        log.error("业务异常", e);
        return Result.build(null, e.getResultCodeEnum());
    }

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        log.error("系统异常", e);
        return Result.build(null, ResultCodeEnum.SYSTEM_ERROR);
    }
}
